package com.sskj.gocoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.util.MD5Util;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.http.JsonCallBack;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.PayPwdSettingActivity;
import com.sskj.gocoin.v.activity.PwdResetActivity;

/**
 * <pre>
 *     author : wk_math
 *     e-mail : wk_math@163.com
 *     time   : 2018/03/30
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class PwdResetPresenter extends BasePresenter<PwdResetActivity> {
    /**
     * 找回密码
     *
     * @param mobile
     * @param password
     * @param code
     */
    public void reset(String mobile, String password, String code) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_PWD)
                .params("opwd", MD5Util.getMd5Value(password))
                .params("opwd1", MD5Util.getMd5Value(password))
                .params("code", code)
                .params("mobile", mobile)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getCode() == 200) {
                            mView.resetSuccess();
                        }
                    }
                });
    }

    /**
     * 修改密码
     *
     * @param password
     */
    public void resetWithOrigin(String password, String code) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHANGE_PWD)
                .params("code", code)
                .params("password", MD5Util.getMd5Value(password))
                .params("password_confirmation", MD5Util.getMd5Value(password))
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getCode() == 200) {
                            mView.resetSuccess();
                        }
                    }
                });
    }

    public void sendCode() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("mobile", MyAppLication.getMobile())
                .params("type", 3)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        mView.sendCodeOk();
                        ToastUtil.showShort(httpListData.getMsg());
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                        mView.sendCodeError();
                    }
                });
    }

    public void sendEmail() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL)
                .params("email", MyAppLication.getMobile())
                .params("is_app", "1")
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.msg);
                        if (body.getCode() == 200) {
                            mView.sendCodeOk();
                        }
                    }
                });
    }

    //验证谷歌验证码
    public void requestGoogleCheck(String googleCode) {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.GOOGLE_LOGIN)
                .params("dyGoodleCommand", googleCode)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<String>> response) {
                        HttpData<String> body = response.body();
                        if (body.getCode() == 200) {
                            mView.googleCheckSuccess();
                        } else {
                            ToastUtil.showShort(body.msg);
                        }
                    }
                });
    }
}
